<script>
	import { serverURL } from './services/httpService'
	export default {
		onLaunch: function() {
			console.log('App Launch')
		},
		onShow: function() {
			// 获取code,openid，token
			console.log('App Show')
			uni.login({
				provider: "weixin",
				success: function (loginRes) {
					// console.log('成功',loginRes);
					const res = loginRes.code 
					uni.request({
						url: `${serverURL}/api/login`,
						method: "POST",
						data: {
							code: res
						},
						success: (e) => {
							const openid = e.data.data.openid
							// 获取token
							uni.request({
								url:`${serverURL}/api/getToken`,
								method: "POST",
								data: {
									openid: openid
								},
								success: (event) => {
									 // console.log(event.data.data.token);
									uni.setStorageSync('token', event.data.data.token);
								}
							})
						}
					})
				}
			})
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
	@import "/wxcomponents/dist/common/index.wxss";
</style>
